<?php

function mpm_itk_add_lang(&$data) {
	global $T;
	switch($data['lang']) {
		default:
			$T['ss']['mpm_itk'] = 'mpm_itk';
			break;
	}
}

function mpm_itk_add_cfg(&$cfg) {
	global $cfg;
	if (!stristr($cfg['sslang'], 'mpm_itk')) {
		$cfg['sslang'].=",mpm_itk";
	}
}

function mpm_itk_generate_host_conf(&$data){
	global $cfg;
	unset($search);
	unset($replace);

	// Generate mpm_itk configuration
	// open virthost.mod_cband.tpl
	$file = $cfg['basedir']."/httpd/templates/mpm_itk.httpd.tpl";
	$mpm_itk_conf = stripslashes(file_get_contents($file));

	// Get system username for domains webcp owner ID
	if($data['type']=="subdomain" || $data['type']=="pointer"){
		$id = $data['id'];
		$data['id']=$data['owner'];
	}

        $dbp = mysql_query("SELECT username FROM users WHERE id=".$data['id']." and level='3' or level='2'");
        if ($dbp) {
                $userdata = mysql_fetch_array($dbp);
                $data['username']=$userdata[0];
        }else return;

	call_hook('user:get:username', $data);
	if($data['type']=="subdomain" || $data['type'] == "pointer") $data['id'] = $id;
		
	$search[] = "{USER}";
	$replace[] = $data['username'];

	$search[] = "{GROUP}";
	if($data['type']=="domain") $replace[] = "g".$data['id'];
	else $replace[] = "g".$data['owner'];

	$mpm_itk_conf = str_replace($search, $replace, $mpm_itk_conf);

	return $mpm_itk_conf;
}

function  mpm_itk_template(&$ret) {
	global $cfg;

	$template['title'] = 'mpm_itk';
	$template['servicename'] = 'httpd';
	$template['active'] = true;
	$template['file'][] = array('filename' => 'mpm_itk');

	$ret[] = $template;
}

?>
